package cool.qingqing.compartor;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author 高山青
 * @Date 2022/1/2  -   15:05
 */
public class CompartorTest {



	public static void main(String[] args) {
		List<Dog> list = new ArrayList<>();
		list.add(new Dog(12,"wc"));
		list.add(new Dog(11,"hz"));
		list.add(new Dog(14,"ll"));
		/*Collections.sort(list, new Comparator<Dog>() {
			@Override
			public int compare(Dog o1, Dog o2) {
				return o1.getAge()-o2.getAge();
			}
		});*/
		/**
		 * lamb表达式的写法
		 */
		Collections.sort(list,(Dog d1,Dog d2)->{
			return d1.getAge()-d2.getAge();
		});
		list.forEach(System.out::print);
		Collections.sort(list,(Dog d1,Dog d2)->{
			return d1.getName().compareTo(d2.getName());
		});
		list.forEach(System.out::print);
	}




}
class Dog{
	private int age;
	private String name;

	public Dog() {
	}

	public Dog(int age, String name) {
		this.age = age;
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		return "Dog{" +
				"age=" + age +
				", name='" + name + '\'' +
				'}';
	}


}